package com.bxs.global;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Data;

@Data
public class JsonResult {
    private int code;
    private String msg;
    private Object data;

    // 默认响应成功
    public JsonResult(ResponseType responseType, Object data){
        this.code = responseType.getCode();
        this.msg = responseType.getDesc();
        this.data = data;
    }

    public static JsonResult success(Object data){
        return new JsonResult(ResponseType.SUCCESS, data);
    }

    public static JsonResult error(Object data){
        return new JsonResult(ResponseType.ERROR, data);
    }

    public static JsonResult inputResult(Object data){
        return new JsonResult(ResponseType.PARAM_ERROR, data);
    }

//    public static void main(String[] args) throws JsonProcessingException {
//        String hello = JsonUtils.toJsonData(new JsonResult(ResponseType.SUCCESS, "hello"));
//        System.out.println(hello);
//    }
}
